﻿using Ids4.Api.Data.Entities;
using Microsoft.AspNetCore.Identity;

namespace Ids4.Api.Data.Mysql
{
    public class MysqlApplicationDbContext : BaseApplicationDbContext<MysqlApplicationDbContext>
    {
        public MysqlApplicationDbContext(DbContextOptions<MysqlApplicationDbContext> options) : base(options)
        {
        }


        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);
            optionsBuilder.EnableSensitiveDataLogging();
            optionsBuilder.UseSnakeCaseNamingConvention();
        }
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
            //mysql字段编辑
            builder.Entity<IdentityUserLogin<int>>().ToTable("user_login").Property(d => d.LoginProvider).HasMaxLength(128);
            builder.Entity<IdentityUserLogin<int>>().ToTable("user_login").Property(d => d.ProviderKey).HasMaxLength(128);
            builder.Entity<IdentityUserToken<int>>().ToTable("user_token").Property(d => d.LoginProvider).HasMaxLength(128);
            builder.Entity<IdentityUserToken<int>>().ToTable("user_token").Property(d => d.Name).HasMaxLength(128);
            builder.Entity<ApplicationUser>().ToTable("user").Property(d => d.NormalizedUserName).HasMaxLength(128);
            builder.Entity<ApplicationRole>().ToTable("role").Property(d => d.NormalizedName).HasMaxLength(128);
            builder.Entity<IdentityRoleClaim<int>>().ToTable("role_claim");
            builder.Entity<IdentityUserClaim<int>>().ToTable("user_claim");
            builder.Entity<IdentityUserRole<int>>().ToTable("user_role");
            builder.Entity<Claims>().ToTable("claim");

        }
    }
}
